package com.ruicar.afs.cloud.manage.mq.file;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ruicar.afs.cloud.common.mq.rabbit.listener.AfsMqBizProcessor;
import com.ruicar.afs.cloud.common.mq.rabbit.message.MqTransCode;
import com.ruicar.afs.cloud.common.util.EmptyUtils;
import com.ruicar.afs.cloud.image.entity.ComAttachmentFile;
import com.ruicar.afs.cloud.image.service.ComAttachmentFileService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description: 贷前合同pdf文件信息保存
 */
@Component
@AllArgsConstructor
public class SyncContractFileDataProcessor implements AfsMqBizProcessor<JSONArray> {

    private final ComAttachmentFileService comAttachmentFileService;

    @Override
    public boolean processMessage(JSONArray entity) throws Exception {
        if(EmptyUtils.isNotEmpty(entity)){
            List<ComAttachmentFile> comAttachmentFiles = JSON.parseArray(JSON.toJSONString(entity), ComAttachmentFile.class);
            comAttachmentFiles.forEach(e->{
                comAttachmentFileService.save(e);
            });
//            return comAttachmentFileService.saveBatch(entity);
        }
        return true;
    }

    @Override
    public MqTransCode getCode() {
        return MqTransCode.WOW_APPLY_MANAGE_ICOS_CONTRACT_PDF;
    }

    @Override
    public boolean reQueueOnFail() {
        return false;
    }

}
